package ua.yandex.skipass;


import ua.yandex.collections.MyArrayList;

public class System {
    private MyArrayList registerBlockedCards = new MyArrayList();
    private int[] passAllowStatistics;
    private int[] passRejectionStatistic;

    public System() {
        PassType[] typesOfPass = PassType.values();
        passAllowStatistics = new int[typesOfPass.length];
        passRejectionStatistic = new int[typesOfPass.length];
    }

    public void blockCard(int id) {
        int indexOfId = ua.yandex.collections.MyCollections.binarySearch(
                registerBlockedCards, id);
        if (indexOfId < 0) {
            indexOfId = -indexOfId - 1;
            registerBlockedCards.add(indexOfId, id);
        }
    }

    public boolean doesCardBlocked(int id) {
        int indexOfId = ua.yandex.collections.MyCollections.binarySearch(
                registerBlockedCards, id);
        return indexOfId < 0;
    }

    public void addOnePassAllow(PassType passType) {
        int passTypeId = passType.ordinal();
        ++passAllowStatistics[passTypeId];
    }

    public void addOnePassRejection(PassType passType) {
        int passTypeId = passType.ordinal();
        ++passRejectionStatistic[passTypeId];
    }

    public int getRejectionStats(PassType passType) {
        return passRejectionStatistic[passType.ordinal()];
    }

    public int getAllowStats(PassType passType) {
        return passAllowStatistics[passType.ordinal()];
    }

    public int getRejectionStats() {
        int summaryStatistics = 0;
        for (int rejectionNumber : passRejectionStatistic) {
            summaryStatistics += rejectionNumber;
        }
        return summaryStatistics;
    }

    public int getAllowStats() {
        int summaryStatistics = 0;
        for (int allowNumber : passAllowStatistics) {
            summaryStatistics += allowNumber;
        }
        return summaryStatistics;
    }

    public SkiPass generateSkiPass(PassFactory factory) {
        return factory.generateSkiPass();
    }

}
